package com.aisi.manager.service.impl;

import com.aisi.manager.mapper.SysRoleMenuMapper;
import com.aisi.manager.service.SysMenuService;
import com.aisi.manager.service.SysRoleMenuService;
import com.aisi.model.dto.system.AssginMenuDto;
import com.aisi.model.entity.system.SysMenu;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author: shenjianZ
 * @Date: 2024/2/18 11:34
 * @Description:
 */

@Service
public class SysRoleMenuServiceIml implements SysRoleMenuService {

    @Resource
    private SysMenuService sysMenuService;

    @Resource
    private SysRoleMenuMapper sysRoleMenuMapper;

    @Override
    public Map<String, Object> findSysRoleMenuByRoleId(Long roleId) {
        List<SysMenu> sysMenuList = sysMenuService.findAllMenus();
        List<Long> roleMenuIds = sysRoleMenuMapper.findSysRoleMenuByRoleId(roleId);
        return Map.of("sysMenuList", sysMenuList, "roleMenuIds", roleMenuIds);
    }

    @Override
    public void doAssign(AssginMenuDto assginMenuDto) {
        sysRoleMenuMapper.deleteSysMenuById(assginMenuDto.getRoleId());
        if(assginMenuDto.getMenuIdList() != null && !assginMenuDto.getMenuIdList().isEmpty()){
            sysRoleMenuMapper.doAssign(assginMenuDto);
        }
    }
}
